/*
 * Copyright (c) 2011.
 *
 * This program is free software: you can redistribute it and/or modify
 * it under the terms of the GNU Lesser General Public License as published by
 * the Free Software Foundation, either version 3 of the License, or
 * (at your option) any later version.
 *
 * This program is distributed in the hope that it will be useful,
 * but WITHOUT ANY WARRANTY; without even the implied warranty of
 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
 * GNU Lesser General Public License for more details.
 *
 * You should have received a copy of the GNU Lesser General Public License
 * along with this program.  If not, see <http://www.gnu.org/licenses/>.
 */

package org.skavookie.expressions.parser

import scala.util.parsing.combinator._
import java.lang.{Byte => JByte}
import org.skavookie.expressions._

/**
 * Created by IntelliJ IDEA.
 * User: joshua
 * Date: 5/27/11
 * Time: 2:50 PM
 * To change this template use File | Settings | File Templates.
 */

abstract class ExprParser[T](implicit manifest: Manifest[T]) extends JavaTokenParsers {
//	lazy val expr =

	val expr: Parser[Expr[T]]
	def litExp: Parser[Expr[T]]

/*	lazy val setExp = symbol <~ "=" ~> expr ^^ { case key ~ value => SetExpr(key, value) }
	lazy val symbol: Parser[Symbol] = ident ^^ { x => Symbol(x) }*/
//	def plus: Parser[Expr[T]] = numExp[T](m) ~ literal("+") ~ numExp[T](m) ^^ { case l ~ _ ~ r => PlusExpr[T](l,r)(l.getNumeric) }
/*
	def minus[T](implicit m: Manifest[T]): Parser[Expr[T]] = numLit(m) ~> lit("-") <~ numLit(m) ^^ { case l ~ r => MinusExpr(l,r) }
	def times[T](implicit m: Manifest[T]): Parser[Expr[T]] = numLit(m) ~> lit("*") <~ numLit(m) ^^ { case l ~ r => TimesExpr(l,r) }
	def negate[T](implicit m: Manifest[T]): Parser[Expr[T]] = lit("-") ~> numLit(m) ^^ { x => NegateExpr(x) }
*/

/*
	def numExp[T](implicit m: Manifest[T]) = numLit[T] | plus[T] |
	def integralExp[T](implicit m: Manifest[T]) = integralLit[T]

	def integralLit[T](implicit m: Manifest[T]): Parser[IntegralExpr[T]] = m.toString match {
		case "byte" => byteLit
		case "long" => longLit
	}
	def typeOf[T](t: T): T = t
	def numLit[T](implicit m: Manifest[T]): Parser[NumericExpr[T]] = m.toString match {
		case "byte" => byteLit ^^ { _.asInstanceOf[NumericExpr[T]] }
		case "long" => longLit ^^ { _.asInstanceOf[NumericExpr[T]] }
		case "double" => doubleLit ^^ { _.asInstanceOf[NumericExpr[T]] }
		case "float" => floatLit ^^ { _.asInstanceOf[NumericExpr[T]] }
	}
	val byteLit = """(?i)([0-9a-f]{2})""".r ^^ { x => LiteralIntegral[Byte](JByte.parseByte(x, 16)) }
  val longLit = """(?i)(-?)(0|[1-9][0-9]*|0x[0-9a-f]+)L|[1-9][0-9]{10,}""".r ^^ { x => LiteralIntegral[Long](x.toLong) }
  val intLit = wholeNumber ^^ { x => LiteralIntegral[Int](x.toInt) }
	val doubleLit = floatingPointNumber ^^ { x => LiteralFractional[Double](x.toDouble) }
	val floatLit = floatingPointNumber ^^ { x => LiteralFractional[Float](x.toFloat) }
*/

}
